package com.cs.excelreadimport.easyexcel.controller;


import com.cs.excelreadimport.easyexcel.service.ExcelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

/*
 * @Description: 直接用浏览器去发送请求
 * @Author: cs
 * @Date: 2024/11/19 15:32
 */
@RestController
@RequestMapping("/excel")
@Slf4j
public class EasyExcelController {

    @Resource
    private ExcelService excelService;


    /*
     * @Description: 单线程导出excel 平均95s
     * @return void
     * @Author: cs
     * @Date: 2024/11/19 15:09
     */
    @GetMapping("/single/export")
    public void singleExport() throws IOException {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        excelService.singleExport();
        stopWatch.stop();
        log.info("单线程去执行导出excel的接口共计耗时： " + stopWatch.getTotalTimeSeconds()+"S");
    }
    /*
     * @Description: 多线程异步并行去导出excel且保证数据一致性 平均耗时 67s
     * @Author: cs
     * @Date: 2024/11/19 15:35
     */
    @GetMapping("/batch/export/order")
    public void batchExportWithOrder() throws IOException {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        excelService.batchExportWithOrder();
        stopWatch.stop();
        log.info("多线程异步并行且保证数据顺序一致去导出excel的接口 共计耗时： " + stopWatch.getTotalTimeSeconds()+"S");
    }

    /*
     * @Description: 多线程异步并行去导出excel 平均耗时 70s
     * @Author: cs
     * @Date: 2024/11/19 15:35
     * 不顺序
     */
    @GetMapping("/batch/export/notorder")
    public void batchExportWithNotOrder() throws IOException {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        excelService.batchExportWithNotOrder();
        stopWatch.stop();
        log.info("多线程异步并行且保证数据顺序一致去导出excel的接口 共计耗时： " + stopWatch.getTotalTimeSeconds()+"S");
    }





}
